import django_filters

from .models import Log


class LogFilter(django_filters.FilterSet):
    user = django_filters.CharFilter(method='get_user_filter')

    class Meta:
        model = Log
        fields = ('user', 'module', 'type')

    def get_user_filter(self, queryset, name, value):
        if value:
            queryset = queryset.filter(user__name__icontains=value)
        return queryset
